# -*- coding: utf-8 -*-

from .img import *


class Bmp(Img):
    __FORMAT__ = 'bmp'
    __MAGIC__ = (b'BM', b'BA', b'CI', b'CP', b'IC', b'PT')

    @classmethod
    def size(cls, fobj):
        rb = fobj.read(26)
        w = int.from_bytes(rb[-8:-4], byteorder='little')
        h = int.from_bytes(rb[-4:], byteorder='little')

        return ImgSize(fobj.file_size, w, h)

    @classmethod
    def test(cls, fobj):
        rb = bytes(fobj.read(2))
        return rb in cls.__MAGIC__
